<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
	<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
	<title>个人注册</title>
	<link rel="icon" href="./img/favicon.ico">

	<link rel="stylesheet" type="text/css" th:href="@{/css/elementui.css}" />
	<link rel="stylesheet" type="text/css" href="./css/all.css"  th:href="@{/css/all.css}" />
	<link rel="stylesheet" type="text/css" href="./css/pages-register.css" />
</head>

<body>
<div id="app">
	<!--页面顶部-->
	<div id="nav-bottom">
		<!--顶部-->
		<div class="nav-top">
			<div class="top">
				<div class="py-container">
					<div class="shortcut">
						<ul class="fl">
							<li class="f-item">
								<span v-if="!loginInfo.username">
									请<a th:href="@{/loginUI}">登录</a>
								</span>
								<span v-if="loginInfo.username">
									{{loginInfo.username}}
									<a href="javascript:void(0)" @click="logout">退出登录</a>
								</span>
								<span>
									<a th:href="@{/registerUI}">免费注册</a>
								</span>
							</li>
						</ul>
						<div class="fr typelist">
							<ul class="types">
								<li class="f-item"><span>我的订单</span></li>

								<li class="f-item"><span><a href="cart.html" target="_blank">我的购物车</a></span></li>
								<li class="f-item"><span><a href="home.html" target="_blank">我的青橙</a></span></li>
								<li class="f-item"><span>青橙会员</span></li>
								<li class="f-item"><span>企业采购</span></li>
								<li class="f-item"><span>关注青橙</span></li>
								<li class="f-item"><span><a href="cooperation.html" target="_blank">合作招商</a></span></li>
								<li class="f-item"><span><a href="shoplogin.html" target="_blank">商家后台</a></span></li>
								<li class="f-item"><span>网站导航</span></li>
							</ul>
						</div>

					</div>
				</div>
			</div>

			<!--头部-->
			<div class="header">
				<div class="py-container">
					<div class="yui3-g Logo">
						<div class="yui3-u Left logoArea">
							<a class="logo-bd" title="青橙"  href="javascript:void(0)" th:href="@{/index}"></a>
						</div>
						<div class="yui3-u Rit searchArea">
							<div class="search">
								<form action="" class="sui-form form-inline">
									<!--searchAutoComplete-->
									<div class="input-append">
										<input type="text" id="autocomplete"  class="input-error input-xxlarge" />
										<button class="sui-btn btn-xlarge btn-danger" type="button">搜索</button>
									</div>
								</form>
							</div>
						</div>

					</div>

				</div>
			</div>
		</div>
	</div>

	<div class="register py-container ">

		<!--register-->
		<div class="registerArea">
			<h3>注册新用户<span class="go">我有账号，去<a th:href="@{/loginUI}">登陆</a></span></h3>
			<div class="info">
        <form class="sui-form form-horizontal">
					<div class="control-group">
						<label class="control-label">手机号：</label>
						<div class="controls">
							<input type="text" placeholder="请输入你的手机号" v-model="pojo.phone" class="input-xfat input-xlarge">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">验证码：</label>
						<div class="controls">
							<input type="text"  v-model="smsCode" placeholder="请输入验证码" class="input-xfat input-xlarge">
							<a style="cursor:pointer" ><span v-if="codeShow" @click="sendSms">点击获取验证码</span></a>
							<a style="cursor:pointer" ><span v-if="!codeShow" class="count">{{count}}秒后重试</span></a>
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">登录密码：</label>
						<div class="controls">
							<input type="password" v-model="pojo.password" placeholder="设置登录密码" class="input-xfat input-xlarge">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">确认密码：</label>
						<div class="controls">
							<input type="password" placeholder="再次确认密码" v-model="password" class="input-xfat input-xlarge">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
						<div class="controls">
							<input name="m1" type="checkbox" value="2" checked=""><span>同意协议并注册《品优购用户协议》</span>
						</div>
					</div>
					<div class="control-group">
						<label class="control-label"></label>
						<div class="controls btn-reg">
							<a class="sui-btn btn-block btn-xlarge btn-danger" href="javascript:void(0)" @click="save">完成注册</a>
						</div>
					</div>
				</form>
				<div class="clearfix"></div>
			</div>
		</div>
		<!--foot-->
		<div class="py-container copyright">
			<ul>
				<li>关于我们</li>
				<li>联系我们</li>
				<li>联系客服</li>
				<li>商家入驻</li>
				<li>营销中心</li>
				<li>手机品优购</li>
				<li>销售联盟</li>
				<li>品优购社区</li>
			</ul>
			<div class="address">地址：北京市昌平区建材城西路金燕龙办公楼一层 邮编：100096 电话：400-618-4000 传真：010-82935100</div>
			<div class="beian">京ICP备08001421号京公网安备110108007702
			</div>
		</div>
	</div>
</div>

<script type="text/javascript" src="./js/all.js"></script>
<script type="text/javascript" src="./js/plugins/jquery/jquery.min.js"></script>
<script type="text/javascript" src="./js/pages/index.js"></script>
<script src="https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js"></script>
<script th:src="@{/js/vue.js}"></script>
<script th:src="@{/js/axios.js}"></script>
<script th:src="@{/js/interceptor.js}"></script>
<script th:src="@{/js/elementui.js}"></script>
<script>
	var vue=new Vue({
		el: '#app',
		data (){
			return {
				pojo: {},
				smsCode:"",
				password:"",
				codeShow : true,
				count: '',
				timer: null,
				loginInfo: {},
				token: ''
			}
		},
		methods:{
			// 打开我的订单
			openMyOrder () {
				// console.log(111)
				if (!this.loginInfo.username) {
					alert("未登录")
					window.location.href='/portal/loginUI'
					return
				}
				window.location.href='/portal/myOrder'
			},
			// 打开我的购物车
			openCart(){
				if(this.loginInfo.username==null){
					alert("请登录")
					window.location.href='/portal/loginUI'
					return
				}
				window.location.href='/portal/cartUI'
			},
			//处理发送验证码的请求
			sendSms(){
				if(this.pojo.phone==undefined){
					this.$message.error('手机号不能为空！！！');
					return ;
				}
				axios.get(`/portal/sendSms?phone=${this.pojo.phone}`).then(response => {
					// console.log(response.data.message);
					if(response.data.message=="成功"){
						this.$message({
							message: '验证码发送成功',
							type: 'success'
						});
					}
					// this.$message(response.data.message);
				});
				//倒计时 60秒
				const TIME_COUNT = 60;
				if (!this.timer) {
					this.count = TIME_COUNT;
					this.codeShow = false;
					this.timer = setInterval(() => {
						if (this.count > 0 && this.count <= TIME_COUNT) {
							this.count--;
						} else {
							this.codeShow = true;
							clearInterval(this.timer);
							this.timer = null;
						}
					}, 1000)
				}
			},
			//点击完成注册
			save (){
				if(this.pojo.phone ==undefined){
					this.$message.error('手机号不能为空！！！');
					return ;
				}
				if(this.smsCode ==""){
					this.$message.error('验证码为空！！！');
					return ;
				}

				if (!(/^1[34578]\d{9}$/.test(this.pojo.phone))) {
					this.$message.error('手机号码格式不正确！！！');
					return ;
				}
				if(this.password!=this.pojo.password){
					// alert("两次输入密码不一致");
					this.$message.error('两次输入密码不一致！！！');
					return ;
				}
				axios.post(`/portal/save?smsCode=${this.smsCode}`,this.pojo).then(response => {
					// console.log(response.data.message);
					this.pojo={};
					this.smsCode="";
					this.password="";

					this.$message({
						message: '恭喜您，注册成功',
						type: 'success'
					});
				});

			},
			showInfo() {
				var user = Cookies.get('qingcheng_user')
				console.log(user)
				// 把字符串转换json对象
				if (user) {
					this.loginInfo = JSON.parse(user)
					// console.log(this.loginInfo)
				}
			},
			logout () {
				// 清空cookie值
				Cookies.set('qingcheng_token', '', {domain: 'localhost'})
				Cookies.set('qingcheng_user', '', {domain: 'localhost'})
				// 回到首页面
				window.location.href='/portal/index'
			},
			wxLogin() {
				if (this.token == '') return
				//把token存在cookie中、也可以放在localStorage中
				Cookies.set('qingcheng_token', this.token, {domain: 'localhost'})
				Cookies.set('qingcheng_user', '', {domain: 'localhost'})
				//登录成功根据token获取用户信息
				axios.get('/portal/getUserInfo').then(response => {
					this.loginInfo = response.data.data.tbUser
					// console.log(this.loginInfo)
					// 将用户信息记录cookie
					Cookies.set('qingcheng_user', this.loginInfo, {domain: 'localhost'})

				})
			}
		},
		created() {
			const querystring = location.search.substring(1)
			const queryary = querystring.split('&')
			const params = queryary[0].split('=')
			this.token = params[1]
			if (this.token) {
				this.wxLogin()
			}
			this.showInfo()
		}
	})
</script>


</body>

</html>